
package edu.faytechcc.csc.gui.search;

import edu.faytechcc.csc.messages.NetworkConnection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToolBar;

/**
 * Please describe what this class does here.
 *
 * CSC 251 0001 DATE:
 *
 * @author Stephanie Mckenzie
 */
public class CreateARGMenuBar
{
    private JMenuBar menuBar;
    private JMenu fileMenu;
    private JToolBar argToolBar;
    private JRadioButtonMenuItem mangaItem;
    private JRadioButtonMenuItem animeItem;
    private ButtonGroup selectButtonGroup;
    private String tableName = "Anime_Table";
    private NetworkConnection conn = null;
    private SearchPanel search;
    private ListPanel list;
    
    public CreateARGMenuBar(NetworkConnection conn, SearchPanel search,
            ListPanel list)
    {
        this.conn = conn;
        this.search = search;
        this.list = list;
        // fill the empty variables
        menuBar = new JMenuBar();
        argToolBar = new JToolBar();
        fileMenu = new JMenu("File");
        mangaItem = new JRadioButtonMenuItem("Manga");
        animeItem = new JRadioButtonMenuItem("Anime", true);
        selectButtonGroup = new ButtonGroup();
        argToolBar.setFloatable(false);// makes it so you can't move it around
        //add actionlisteners
        mangaItem.addActionListener(new itemActionListener());
        animeItem.addActionListener(new itemActionListener());
        
        //set the feile menues mnemonic
        fileMenu.setMnemonic(KeyEvent.VK_F);
        mangaItem.setMnemonic(KeyEvent.VK_M);
        animeItem.setMnemonic(KeyEvent.VK_A);
        
        // add manga and anime buttons to button group and file menu
        selectButtonGroup.add(mangaItem);
        selectButtonGroup.add(animeItem);
        fileMenu.add(mangaItem);
        fileMenu.add(animeItem);

        // add menu's and items to the menubar
        menuBar.add(fileMenu);
        menuBar.add(argToolBar);
        search.setTable(tableName);
    }

    /**
     * 
     * @return menuBar
     */
    public JMenuBar getFileMenu()
    {
        return menuBar;
    }

    private class itemActionListener implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            if(mangaItem.isSelected())
            {
                tableName = "Manga_Table";
            }
            else
            {
                tableName = "Anime_Table";
            }
            search.setTable(tableName);
            list.setTableName(tableName);
        }
    }
}
